home *** CD-ROM | disk | FTP | other *** search
- /*
- *--- PRequestBuf.cpp -----------------------------------------------------
- * Copyright (c) 1995-96 Adobe Systems Incorporated. All rights reserved.
- * Created on Thu, Oct 19, 1995 @ 8:17 PM by Paul Ferguson.
- *
- * Description: For notes about this class, refer to the
- * header file PRequestBuf.h
- *------------------------------------------------------------------------
- */
-
- //#include "PageMakerMemory.h"
- #include "PMCQErrs.h"
- #include "CIBasic.h"
- #include "CIInterfaceManager.h"
- #include "PMInterfaceIDs.h"
-
- extern PMMessage * gPMMessage;
-
- #include "PRequestBuf.h"
-
- PRequestBuf::PRequestBuf(size_t bufSize) throw (PMErr)
- : bufHdl(0)
- {
- CIBasic * basicInterface;
- gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
- bufPtr = (char *) basicInterface->PMMemAlloc(bufSize);
- gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
-
- if (bufPtr == NULL)
- throw CQ_FAILURE;
-
-
- curCh = bufPtr;
- }
-
- PRequestBuf::PRequestBuf(void * h)
- : bufHdl(0), bufPtr((char *) h)
- {
- curCh = bufPtr;
- }
-
- PRequestBuf::~PRequestBuf()
- {
- if (bufPtr)
- {
- CIBasic * basicInterface;
- gPMMessage->pInterfaceMgr->AcquirePMInterface((unsigned long)PMIID_BASIC, (void **) &basicInterface);
- basicInterface->PMMemFree(bufPtr);
- gPMMessage->pInterfaceMgr->ReleasePMInterface(basicInterface);
- }
- }
-
- PRequestBuf& PRequestBuf::operator<< (short aShort)
- {
- *((short *) curCh) = aShort;
-
- curCh += 2;
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (unsigned short aShort)
- {
- *(unsigned short *) curCh = aShort;
- curCh += 2;
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (long aLong)
- {
- *(long *) curCh = aLong;
- curCh += 4;
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (unsigned long aLong)
- {
- *(unsigned long *) curCh = aLong;
- curCh += 4;
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (const char * aString)
- {
- if (aString)
- {
- register char * dest = curCh;
- register const char * src = aString;
- while (*dest++ = *src++) // copy string, and null terminator
- ;
-
- if (long(dest) & 0x01) ++dest; // make sure have even alignment
- curCh = dest;
- }
- else
- {
- *curCh++ = '\0';
- *curCh++ = '\0';
- }
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (const unsigned char * aString) // A Pascal string
- {
- if (aString)
- {
- register unsigned char * dest = (unsigned char *) curCh;
- register const unsigned char * src = aString;
- register size_t strLen = *src++; // Get length byte
-
- while ( (strLen--) && (*dest++ = *src++) )
- ; // copy string, and null terminator
-
- *dest++ = '\0';
-
- if (long(dest) & 0x01) ++dest; // make sure have even alignment
- curCh = (char *) dest;
- }
- else
- {
- *curCh++ = '\0';
- *curCh++ = '\0';
- }
-
- return *this;
- }
-
- PRequestBuf& PRequestBuf::operator<< (PRequestBuf& aBuf)
- {
- if (&aBuf == this) return *this; // don't copy onto self.
-
- register size_t size = aBuf.Size();
- register const char * src = aBuf; // start of its buffer
- register char * dest = curCh;
-
- while (size--)
- *dest++ = *src++;
-
- curCh += aBuf.Size();
-
- return *this;
- }
-
- // end of PRequestBuf.cpp
-